<?php
class controller{
	protected $tplvar;
	protected $tplname;
	public function __construct(){
				
	}
	public static function error($str='error'){
		exit($str);
	}
	public function M($table){	
		try{	
			$mod=new model();
			$mod->setTable($table);	
		}
		catch(PDOException $e){
			self::error($e->getMessage());			
		}					
		return $mod;
	}
	//高级模型 todo
	public static function D(){
		
	}
	
	
	
	//展示视图
	public function assign($var,$data){
		$this->tplvar=array($var=>$data);
	}
	public function display($tpl=""){
		$controller=CONTROLLER_NAME;
		$action=ACTION_NAME;
		if($tpl==""){
			$tpl=$controller.'/'.$action;
		}else{
			$tpl=explode("/",$tpl);
			$tpl[0]==(count($tpl)==1)?$controller:$tpl[0];			
			$tpl=$tpl[0].'/'.$tpl[1];
		}		
		$this->tplname=	$tpl;
		try{
			echo view::show()->make($this->tplname, $this->tplvar)->render();
		}catch(InvalidArgumentException $e){
			self::error($e->getMessage());	
		}
		
	}
	
}